test_attr           Return

左図は「test_att」rを起動し、Directoryの属性を表示したところです

FormにButtonを配置しDirectoryとFileを選択できるようにし、ラベル、CheckBoxを配置し、
属性を表示しております
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test_attr
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        void DispAtr(string[] str)
        {
            checkBox1.Checked = false;
            checkBox2.Checked = false;
            checkBox3.Checked = false;
            checkBox4.Checked = false;
            checkBox5.Checked = false;
            checkBox6.Checked = false;
            checkBox7.Checked = false;

            foreach (string s0 in str)
            {
                if (s0.Contains("ReadOnly")==true)
                {
                    checkBox1.Checked = true; ;
                }
                if (s0.Contains("Hidden")==true)
                {
                    checkBox2.Checked = true; ;
                }
                if (s0.Contains("System")==true)
                {
                    checkBox3.Checked = true; ;
                }
                if (s0.Contains("Directory")==true)
                {
                    checkBox4.Checked = true; ;
                }
                if (s0.Contains("Archive")==true)
                {
                    checkBox5.Checked = true; ;
                }
                if (s0.Contains("Encrypted")==true)
                {
                    checkBox6.Checked = true; ;
                }
                if (s0.Contains("Temporary")==true)
                {
                    checkBox7.Checked = true; ;
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)  //Open Dir
        {
            folderBrowserDialog1.SelectedPath = "";
            folderBrowserDialog1.ShowDialog();
            string dirName = folderBrowserDialog1.SelectedPath;
            label3.Text = "DIR";
            label4.Text = dirName;
            if(dirName=="")
            {
                return;
            }
            var directoryInfo = new DirectoryInfo(dirName);
            label1.Text = directoryInfo.Attributes.ToString();
            string[] s = (directoryInfo.Attributes.ToString()).Split(',');
            DispAtr(s);
        }

        private void button3_Click(object sender, EventArgs e) //Open File
        {
            openFileDialog1.FileName = "";
            openFileDialog1.ShowDialog();
            string fname = openFileDialog1.FileName;
            if(fname=="")
            {
                return;
            }
            System.IO.FileInfo fi = new System.IO.FileInfo(fname);

            string[] s = (fi.Attributes.ToString()).Split(',');
            DispAtr(s);
            label1.Text = fi.Attributes.ToString();
            label3.Text = "File";
            label4.Text = fname;

        }
    }
}



左図はプログラムのソースで、
var directoryInfo = new DirectoryInfo(dirName);と
System.IO.FileInfo fi = new System.IO.FileInfo(fname)で
DirectoryとFileのAttributeを取得し、

directoryInfo.Attributes.ToString();と
fi.Attributes.ToString();でStringに格納

string[] s = (directoryInfo.Attributes.ToString()).Split(',');と
string[] s = (fi.Attributes.ToString()).Split(',');で配列とし

DispAtr(string[] str)に配列を渡し、属性を表示させました